|
|
|
|
|
|
|
Figure 14.1.
Displaying the results
of a simple error handler. |
|
|
|
|
|
|
|
|
The next line tells Visual Basic what to do after the error is handled. In this case, Visual Basic resumes execution with the line of program code that immediately follows the line that caused the error (Resume at the Next line). |
|
|
|
|
|
|
|
|
When Visual Basic resumes execution, the routine hits the line that tells Visual Basic to go to the exit routine (Goto LocalExit). Notice again the naming convention for the exit routine. All exit jump labels in this book are called LocalExit. |
|
|
|
|
|
|
|
|
Handling Cascading Errors |
|
|
|
|
|
|
|
|
What happens if you get an error within your error routine? Although it isn't fun to think about, it can happen. When an error occurs inside the error-handling routine, Visual Basic looks for the next declared error routine. This would be an error routine started in the previous calling routine using the On Error Goto label statement. If no error routine is available, Visual Basic halts the program with a fatal error. |
|
|
|
|
|
|
|
|
As an example, let's add a new button to the BASICERR project and create a cascading error condition. Set the button's Name property to cmdCascadeErr and its Caption property to Cascade. First, create a new Sub procedure called CreateErr. Then enter the code from Listing 14.3. |
|
|
|
|
|
|
|
|
Listing 14.3. Coding the CreateErr routine. |
|
|
|
|
|
|
|
|
Public Sub CreateErr()
'
' create an internal error
'
On Error GoTo LocalErr
'
Dim strMsg As String
Dim intValue As Integer
'
intValue = 900000 ' create an error |
|
|
|
|
|